var typeid;

function initPage(id, name) {
	typeid = id;
	// tabs for the center
	var tabs = new Ext.TabPanel({
				id : 'tabs',
				region : 'center',
				closable : true,
				resizeTabs : true,
				minTabWidth : 135,
				tabWidth : 135,
				deferredRender : false,
				enableTabScroll : true,
				margins : '3 3 3 0',
				items : []
			});

	var tree = new Ext.tree.TreePanel({
		region : 'west',
		id : 'tree',
		title : '资产分类',
		split : false,
		width : 200,
		collapsible : false,
		layoutConfig : {
			animate : true
		},
		margins : '3 3 3 3',
		cmargins : '3 3 3 3',
		// onlyLeafCheckable : true,
		autoScroll : true,
		animate : true,
		rootVisible : true,
		loader : new Ext.tree.TreeLoader({
					dataUrl : context + '/system/ddindexshow.do?method=tree',
					baseParams : {

		}
				}),
		root : new Ext.tree.AsyncTreeNode({
					allowChildren : true,
					expanded : true,
					text : name, // 节点名称
					draggable : false, // 是否支持拖动
					iconCls : 'root',
					cls : 'rootFont',
					id : id
				}),
		listeners : {
			'click' : function(node) {
				/*
				 * if (node.isExpanded()) { node.collapse(); } else {
				 * node.expand(); }
				 */
				initQueryList_edit('_' + node.id, 'gzlist', function() {
					Ext.getCmp('gzlist_' + node.id).setTitle(node.text);
				}, '', '', tabs, 'typeId=' + node.id);
			},
			'checkchange' : function(node, checked) {
				if (checked) {
					if (selectedLanmuNode) {
						selectedLanmuNode.attributes.checked = false;
						selectedLanmuNode.ui.checkbox.checked = false;
					}

					selectedLanmuNode = node;
				}
			}
		}
	})

	var win = new Ext.Window({
				id : "win_" + id,
				title : name + '_编辑',
				closable : false,
				resizable : false,
				// maximizable : true,
				width : 700,
				height : 465,
				border : false,
				plain : true,
				layout : 'border',
				modal : true,
				listeners : {
					'show' : function() {
						initQueryList_edit('_' + id, 'gdzclist', function() {
									Ext.getCmp('gdzclist_' + id)
											.setTitle(name);
								}, '', '', tabs, 'typeId=' + id);
					}
				},
				items : [tree, tabs]
			});

	win.show(this);
}

/**
 * render cell
 * @param {} value
 * @param {} cellmeta
 * @param {} record
 * @param {} rowIndex
 * @param {} columnIndex
 * @param {} store
 * @return {}
 */
function renderHeader(value, cellmeta, record, rowIndex, columnIndex, store) {
	var fieldName = Ext.getCmp('gdzctempdjlist_' + typeid).getColumnModel().getDataIndex(columnIndex);
	
	if (fieldName == 'TNAME') {
		var resultString = String.format('<a title="点击进行资产登记" href="' + context
						+ '/app/gdzc.do?method=neu&id={0}">{1}</a>',
				record.data['ID'], value);

		return resultString;
	} else if (fieldName == 'TDATE') {
		return formatDate(value);
	} 
	return value;
}